; tileprop bits:   000000ei event impassible

tilesize	=16
scrw		=16
scrh		=12
scrsize	=scrw*scrh
FPSTRIDE =FIXP_STRIDE


tileprops:
; 		   0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
	.db $00,$01,$01,$01,$03,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00   ; 0


testcolmap:  ;to be copied into wram
;	 	   0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15
   .db $00,$00,$00,$00,$00,$00,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00   ; 0
   .db $00,$00,$00,$00,$00,$00,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00   ; 1
   .db $00,$00,$00,$00,$00,$00,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00   ; 2
   .db $00,$00,$00,$05,$05,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00   ; 3
   .db $00,$00,$00,$05,$00,$05,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00   ; 4
   .db $00,$00,$00,$00,$05,$00,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00   ; 5
   .db $00,$04,$00,$05,$00,$00,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00   ; 6
   .db $00,$00,$00,$00,$00,$00,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00   ; 7
   .db $00,$00,$00,$00,$00,$00,$01,$01,$01,$01,$00,$00,$00,$01,$01,$01   ; 8
   .db $00,$01,$01,$00,$00,$00,$01,$01,$01,$01,$00,$00,$00,$01,$01,$01   ; 9
   .db $00,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00   ; 10
   .db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00   ; 11





macro tilediv
	cmp	#$80
	ror	a
	cmp	#$80
	ror	a
	cmp	#$80
	ror	a
	cmp	#$80
	ror	a
endm

_collidemap:  ; ( w h -- )  width and height in tiles (16x16)
	@width=TEMP0
	@height=TEMP1
	@status=TEMP2 ;bitmask
	@NX=TEMP4
	@NY=TEMP6
	@EX=TEMP8 ; edge x,y
	@EY=TEMP10

	@lwall=1
	@rwall=2
	@floor=4
	@ceiling=8

	pla
	sta @height
	pla
	sta @width

	lda OBJ_INDEX
	tax


	; init
	;	add vel to pos and store in temp coords
		clc
		lda ObjectX,X
		adc ObjectVX,X
		sta @NX
		lda ObjectX+FPSTRIDE,X
		adc ObjectVX+FPSTRIDE,X
		sta @NX+1
		lda ObjectY,X
		adc ObjectVY,X
		sta @NY
		lda ObjectY+FPSTRIDE,X
		adc ObjectVY+FPSTRIDE,X
		sta @NY+1
	;  reset status
		lda #0
		sta @status

	; up/down
@updown
	;  if velocity is zero skip this
		lda ObjectVY,X
		ora ObjectVY+FPSTRIDE,X
		beq @leftright
		; positive/negative
		lda ObjectVY+FPSTRIDE,X
		bpl @checkdown
@checkup
		; x  ny
		lda ObjectX,X
		sta @EX
		lda ObjectX+FPSTRIDE,X
		sta @EX+1
		lda @NY
		sta @EY
		lda @NY+1
		sta @EY+1

		jmp @leftright
@checkdown
		; x  ny h +
		lda ObjectX,X
		sta @EX
		lda ObjectX+FPSTRIDE,X
		sta @EX+1
		lda @NY
		sta @EY
		clc
		lda @NY+1
		adc @height
		sta @EY+1

	; left/right
@leftright
	;  if velocity is zero skip this
		lda ObjectVX,X
		ora ObjectVX+FPSTRIDE,X
		beq @done
		lda ObjectVX+FPSTRIDE,X
		bpl @checkdown
@checkleft
		; nx ny
		lda @NX
		sta @EX
		lda @NX+1
		sta @EX+1
		lda @NY
		sta @EY
		lda @NY+1
		sta @EY+1
		jmp @done
@checkright
		; nx w +  ny
		lda @NX
		sta @EX
		lda @NX+1
		clc
		adc @width
		sta @EX+1
		lda @NY
		sta @EY
		lda @NY+1
		sta @EY+1


@done
	vmnext

@veplus ; vertical edge increment
	inc @EX+1
	rts
@heplus ; horizontal edge increment
	inc @EY+1
	rts

@plusvy:



mappoint:  ; fetch tile at fixed point coordinates - the MSB is our row/col :)
